package com.apes.fn.crm.customerExpand;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apes.fn.business.carAccident.repository.CarAccidentRepository;
import com.apes.fn.business.fixedLoss.repository.LossQuotationRepository;
import com.apes.fn.server.pickUpCar.model.PickUpCar;
import com.apes.fn.server.pickUpCar.repository.PickUpCarRepository;
import com.apes.fn.server.servicePlan.repository.ServicePlanRepository;
import com.apes.fn.server.servicePlan.service.ServicePlanceService;
import com.apes.framework.api.DomainService;
import com.apes.framework.api.SpringManager;
import com.apes.framework.jpa.generator.service.SequenceService;
import com.apes.framework.jpa.spec.JpaDsl;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.framework.query.ApesDao;
import com.apes.framework.util.MapUtil;
import com.apes.scm.masterdata.car.model.CarConfiguration;
import com.apes.scm.masterdata.car.repository.CarConfigurationRepository;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.frame.repository.DeptRepository;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.party.repository.PartyRoleRepository;
import com.apes.scm.masterdata.party.service.PartyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 * 会员车辆扩展信息DAO
 */
@Component
public class FnCustomerExpandDao extends ApesDao {

    public JSONArray findNoCreateInfoData(JSONObject param){
        String sSQL = "select b.id\n" +
                "from FN_CUSTOMER_EXPAND b,(select *\n" +
                "from (select VENDOR_CODE,CAR_LICENSE,max(a.CREATE_DATE)CREATE_DATE\n" +
                "from FN_CUSTOMER_EXPAND A\n" +
                "where CAR_LICENSE is not null\n" +
                "   and VENDOR_CODE is not null \n" +
                "      and not exists(select id from FN_CUSTOMER_info c where a.CAR_LICENSE =c.CAR_LICENSE and a.VENDOR_CODE = c.VENDOR_CODE )\n" +
                "group by VENDOR_CODE,CAR_LICENSE)\n" +
                "where ROWNUM<5000) a\n" +
                "where a.CAR_LICENSE = b.CAR_LICENSE\n" +
                "and a.VENDOR_CODE = b.VENDOR_CODE\n" +
                "and a.CREATE_DATE = b.CREATE_DATE";

        return toJSONArray(find(sSQL, param));
    }

    public JSONArray findNoCreateInfoDataByEmptyVendorCode(JSONObject param){
        String sSQL = "select b.id\n" +
                "from FN_CUSTOMER_EXPAND b,(select *\n" +
                "from (select VENDOR_CODE,CAR_LICENSE,max(a.CREATE_DATE)CREATE_DATE\n" +
                "from FN_CUSTOMER_EXPAND A\n" +
                "where CAR_LICENSE is not null\n" +
                "      and not exists(select id from FN_CUSTOMER_info c where a.CAR_LICENSE =c.CAR_LICENSE  )\n" +
                "group by VENDOR_CODE,CAR_LICENSE)\n" +
                "where ROWNUM<5000) a\n" +
                "where a.CAR_LICENSE = b.CAR_LICENSE\n" +
                "and a.CREATE_DATE = b.CREATE_DATE";

        return toJSONArray(find(sSQL, param));
    }


}
